/*
 * Copyright 2004 Sun Microsystems, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package org.nanotek.cms.domain;

import org.nanotek.util.Base;

/**
 * Bean for link elements of Atom feeds.
 * <p>
 * @author Alejandro Abdelnur
 * @author Dave Johnson (updated for Atom 1.0)
 */
@SuppressWarnings("serial")
public class Link implements Base<Long>,Cloneable {
//    
//    private ObjectBean _objBean;
    
    private Long id; 
    private String href;
    private String hrefResolved;
    private String rel = "alternate";
    private String type;
    private String hreflang;
    private String title;
    private long   length;

    /**
     * Default constructor. All properties are set to <b>null</b>.
     * <p>
     *
     */
    public Link() {
//        _objBean = new ObjectBean(this.getClass(),this);
    }

    /**
     * Set the length
     * <p>
     * @param length The length to set.
     */
    public void setLength(long length) {
        this.length = length;
    }

	@Override
	public Long getId() {
		return id;
	}
	
	private void setId(Long id) 
	{ 
		this.id = id; 
	}
	
    /**
     * Creates a deep 'bean' clone of the object.
     * <p>
     * @return a clone of the object.
     * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
     *
     */
//    public Object clone() throws CloneNotSupportedException {
//        return _objBean.clone();
//    }

    /**
     * Indicates whether some other object is "equal to" this one as defined by the Object equals() method.
     * <p>
     * @param other he reference object with which to compare.
     * @return <b>true</b> if 'this' object is equal to the 'other' object.
     *
     */
//    public boolean equals(Object other) {
//        return _objBean.equals(other);
//    }

    /**
     * Returns a hashcode value for the object.
     * <p>
     * It follows the contract defined by the Object hashCode() method.
     * <p>
     * @return the hashcode of the bean object.
     *
     */
//    public int hashCode() {
//        return _objBean.hashCode();
//    }

    /**
     * Returns the String representation for the object.
     * <p>
     * @return String representation for the object.
     *
     */
//    public String toString() {
//        return _objBean.toString();
//    }

    /**
     * Returns the link rel.
     * <p>
     * @return the link rel, <b>null</b> if none.
     *
     */
    public String getRel() {
        return rel;
    }

    /**
     * Sets the link rel.
     * <p>
     * @param rel the link rel,, <b>null</b> if none.
     *
     */
    public void setRel(String rel) {
        //TODO add check, ask P@ about the check
        this.rel = rel;
    }

    /**
     * Returns the link type.
     * <p>
     * @return the link type, <b>null</b> if none.
     *
     */
    public String getType() {
        return type;
    }

    /**
     * Sets the link type.
     * <p>
     * @param type the link type, <b>null</b> if none.
     *
     */
    public void setType(String type) {
       this.type = type;
    }

    /**
     * Returns the link href.
     * <p>
     * @return the link href, <b>null</b> if none.
     *
     */
    public String getHref() {
        return href;
    }

    /**
     * Sets the link href.
     * <p>
     * @param href the link href, <b>null</b> if none.
     *
     */
    public void setHref(String href) {
        this.href = href;
    }

    public void setHrefResolved(String hrefResolved) {
        this.hrefResolved = hrefResolved;
    }

    public String getHrefResolved() {
        return this.hrefResolved != null ? this.hrefResolved : this.href;
    }

    /**
     * Returns the link title.
     * <p>
     * @return the link title, <b>null</b> if none.
     *
     */
    public String getTitle() {
        return this.title;
    }

    /**
     * Sets the link title.
     * <p>
     * @param title the link title, <b>null</b> if none.
     *
     */
    public void setTitle(String title) {
    	this.title = title;
    }

    /**
     * Returns the hreflang
     * <p>
     * @return Returns the hreflang.
     * @since Atom 1.0
     */
    public String getHreflang() {
        return this.hreflang;
    }
    
    /**
     * Set the hreflang
     * <p>
     * @param hreflang The hreflang to set.
     * @since Atom 1.0
     */
    public void setHreflang(String hreflang) {
    	this.hreflang = hreflang;
    }
    
    /**
     * Returns the length
     * <p>
     * @return Returns the length.
     */
    public long getLength() {
        return this.length;
    }

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((href == null) ? 0 : href.hashCode());
		result = prime * result
				+ ((hrefResolved == null) ? 0 : hrefResolved.hashCode());
		result = prime * result
				+ ((hreflang == null) ? 0 : hreflang.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + (int) (length ^ (length >>> 32));
		result = prime * result + ((rel == null) ? 0 : rel.hashCode());
		result = prime * result + ((title == null) ? 0 : title.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Link other = (Link) obj;
		if (href == null) {
			if (other.href != null)
				return false;
		} else if (!href.equals(other.href))
			return false;
		if (hrefResolved == null) {
			if (other.hrefResolved != null)
				return false;
		} else if (!hrefResolved.equals(other.hrefResolved))
			return false;
		if (hreflang == null) {
			if (other.hreflang != null)
				return false;
		} else if (!hreflang.equals(other.hreflang))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (length != other.length)
			return false;
		if (rel == null) {
			if (other.rel != null)
				return false;
		} else if (!rel.equals(other.rel))
			return false;
		if (title == null) {
			if (other.title != null)
				return false;
		} else if (!title.equals(other.title))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}
    
}
